package com.ruoyi.project.system.controller;

import java.util.List;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONStrFormater;
import cn.hutool.json.JSONUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysAgreement;
import com.ruoyi.project.system.service.ISysAgreementService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * @author jjp
 * @date 2020-04-14
 */
@RestController
@RequestMapping("/system/agreement/")
public class SysAgreementController extends BaseController
{
    @Autowired
    private ISysAgreementService sysAgreementService;

    /**
     * 查询所有协议
     */
    @PreAuthorize("@ss.hasPermi('system:agreement:list')")
    @GetMapping("list")
    public TableDataInfo list(SysAgreement sysAgreement)
    {
        startPage();
        List<SysAgreement> list = sysAgreementService.selectSysAgreementList(sysAgreement);
        return getDataTable(list);
    }

    /**
     * 根据 id 获取单个协议内容
     */
    @PreAuthorize("@ss.hasPermi('system:agreement:query')")
    @GetMapping(value = "{agreementId}")
    public AjaxResult getInfo(@PathVariable("agreementId") Long agreementId)
    {
        return AjaxResult.success(sysAgreementService.selectSysAgreementById(agreementId));
    }

    /**
     * 新增协议
     */
    @PreAuthorize("@ss.hasPermi('system:agreement:add')")
    @Log(title = "添加协议", businessType = BusinessType.INSERT)
    @PostMapping(value = "addAgreement")
    public AjaxResult add(@RequestBody SysAgreement sysAgreement)
    {
        return toAjax(sysAgreementService.insertSysAgreement(sysAgreement));
    }

    /**
     * 修改协议
     */
    @PreAuthorize("@ss.hasPermi('system:agreement:edit')")
    @Log(title = "修改协议", businessType = BusinessType.UPDATE)
    @PutMapping("updateAgreement")
    public AjaxResult edit(@RequestBody SysAgreement sysAgreement)
    {
        return toAjax(sysAgreementService.updateSysAgreement(sysAgreement));
    }

    /**
     * 删除协议
     */
    @PreAuthorize("@ss.hasPermi('system:agreement:remove')")
    @Log(title = "删除协议", businessType = BusinessType.DELETE)
	@DeleteMapping("{agreementIds}")
    public AjaxResult remove(@PathVariable Long[] agreementIds)
    {
        return toAjax(sysAgreementService.deleteSysAgreementByIds(agreementIds));
    }

    @PostMapping(value = "/QueryAgr")
    public AjaxResult queryAgre(@RequestBody SysAgreement sysAgreement)
    {
        return AjaxResult.success(sysAgreementService.selectSysAgreementList(sysAgreement));
    }


}
